/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game;

import java.awt.*;

/**
 *
 * @author pedroxx
 */
public class Screen extends Canvas{
    
    private int x, y, dx, dy;                   
    
    Image buffer;
    Graphics gBuff;    
    
    public Screen() {
        x = 0;
        y = 0;
        dx = 1;
        dy = 1;                        
    }
    
    public void refresh(){        
        x += dx;
        y += dy;
        if( x < 0 || x > getWidth()-40){
            dx *= -1;
        }
        if( y < 0 || y > getHeight()-40){
            dy *= -1;
        }
    }
    
    @Override
    public void paint(Graphics g) {
        //g.setClip(x, y, 40, 40);
        g.setColor(Color.decode("0xFF00FF"));
        g.fillRect(x, y, 40, 40);
        
        g.setColor(Color.decode("0xFFFFFF"));
        g.drawString("hola mundo", 30, 30);
        g.drawString("hello world!", 30, 30);
        g.drawString("hola gente", 50, 50);
    }
    
    @Override
    public void update(Graphics grphcs) {
                                
        Rectangle rect = grphcs.getClipBounds();
        
        if(buffer == null){
            buffer = createImage(rect.width, rect.height);
        }        
        gBuff = buffer.getGraphics();
                
        
        gBuff.setColor(Color.decode("0x000000"));
        gBuff.fillRect(0, 0, rect.width, rect.height);
        
        paint(gBuff);
        
        grphcs.drawImage(buffer, 0, 0, this);
    }
}